﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Transcend.DP3.Helper
{
	/// <summary>
	/// 异常帮助类，用于测试并且抛出常用异常
	/// </summary>
	public class ExHelper
	{

		/// <summary>
		/// 测试对象值，为空则抛出ArgumentException
		/// </summary>
		/// <param name="testValue">测试值</param>
		/// <param name="exMessage">异常信息</param>
		internal static void NotNull(object testValue, string exMessage)
		{
			if (testValue == null) throw new ArgumentException(exMessage);
		}

		/// <summary>
		/// 测试字符串值，为空则抛出ArgumentException
		/// </summary>
		/// <param name="testValue">测试值</param>
		/// <param name="exMessage">异常信息</param>
		internal static void NotEmpty(string testValue, string exMessage)
		{
			if (string.IsNullOrEmpty(testValue)) throw new ArgumentException(exMessage);
		}

		/// <summary>
		/// 抛出InvalidOperationException
		/// </summary>
		/// <param name="expr"></param>
		/// <param name="format"></param>
		internal static void InvalidOperation(string exMessage)
		{
			throw new InvalidOperationException(exMessage);
		}

		internal static void InvalidOperation(string format, object data)
		{
			InvalidOperation(string.Format(format, data));
		}

		/// <summary>
		/// 抛出ArgumentException
		/// </summary>
		/// <param name="format"></param>
		internal static void InvalidArgument(string exMessage)
		{
			throw new ArgumentException(exMessage);
		}

		/// <summary>
		/// 抛出ArgumentException
		/// </summary>
		/// <param name="exMessage"></param>
		internal static void InvalidArgument(string format, params object[] data)
		{
			InvalidArgument(string.Format(format, data));
		}

	}
}
